import Vue from 'vue'
// normalize.css 第三方包
import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import locale from 'element-ui/lib/locale/lang/en' // lang i18n
// 全局样式
import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'
// 导入图标
import '@/icons' // icon
// 导航守卫
import '@/permission' // permission control

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
// Mockjs数据
if (process.env.NODE_ENV === 'production') {
  const { mockXHR } = require('../mock')
  mockXHR()
}

// 安装elementUI，配置语言包
Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui，按如下方式声明
// Vue.use(ElementUI)

Vue.config.productionTip = false

// 全局注册指令
// Vue.directive('指令名',{配置对象})
Vue.directive('permission', {
  inserted(el, binding) {
    // console.log(el);  // 指令所在的DOM节点
    // console.log(binding); // 指令信息
    console.log(binding.value) // 指令后面接数据内容==>每个按钮对应指令对应的标识
    // points 该用户拥有的按钮权限标识
    const points = store.state.user.userInfo?.roles?.points || []
    if (!points.includes(binding.value)) {
      el.remove()
      // el.disabled = true
    }
    console.log('insertedinsertedinserted')
  }
})

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
